<?php
/**
 * Nguoi tao: Tuanpm
 * Ngay tao: 20/02/2013
 * Y nghia: Cap nhat xu ly tai lieu hoc tap
 */	
class mtl_reminderController extends  Zend_Controller_Action {
	public function auth(){
        $url = Efy_Init_Config::_getCurrentHttpAndHost();
        if (($_SESSION['STAFF_PERMISSTION'] == 'ADMIN_SYSTEM') || ($_SESSION['STAFF_PERMISSTION'] == 'ADMIN_OWNER')){
            $url = $url .'public/error/index/';
            $this->_redirect($url);
        }
    }
	public function init(){
		Zend_Loader::loadClass('mtl_modReminder');		
		Zend_Loader::loadClass('Zend_Json');	    
		//Load cau hinh thu muc trong file config.ini
        $tempDirApp = Zend_Registry::get('conDirApp');
		$this->_dirApp = $tempDirApp->toArray();
		$this->view->dirApp = $tempDirApp->toArray();
		//Lay duong dan thu muc goc (path directory root)
		$this->view->baseUrl = $this->_request->getBaseUrl() . "/public/";
		if (!$this->_request->isXmlHttpRequest()){
			//Cau hinh cho Zend_layout
			Zend_Layout::startMvc(array(
				    'layoutPath' => $this->_dirApp['layout'],
				    'layout' => 'index'			    
				    ));	
			//Load cac thanh phan cau vao trang layout (index.phtml)
			$response = $this->getResponse();
			//Ky tu dac biet phan tach giua cac phan tu
			$this->view->delimitor 	= "!~~!";	
			//Load cau hinh thu muc trong file config.ini de lay ca hang so dung chung
	        $tempConstPublic = Zend_Registry::get('ConstPublic');
			$this->_ConstPublic = $tempConstPublic->toArray();	
			//Lay cac hang so su dung trong JS public
			$objConfig = new Efy_Init_Config();
			$objConst = new Efy_Init_Const();
			$this->view->JSPublicConst = $objConfig->_setJavaScriptPublicVariable();		
			$this->view->UrlAjax = $objConfig->_setUrlAjax();
			$arrConst = $objConst->_setProjectPublicConst();
			$this->view->arrConst = $arrConst;
			// Load tat ca cac file Js va Css
			$this->view->LoadAllFileJsCss = Efy_Publib_Library::_getAllFileJavaScriptCss(''
				,'efy-js'
				,'print.js,ajaxupload.3.5.js,fg.menu.js,jquery.maskedinput-1.3.js'
				,','
				,'js')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-style','print.css,simpleModal.css,fg.menu.css,jquery.multiselect.css',',','css')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-style','chosen/chosen.css',',','css')
			.Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','mtl/reminder.js',',','js');			
			//Dinh nghia current modul code
			$this->view->currentModulCode = "REMINDER";
			$this->view->currentModulCodeForLeft = $this->_request->getParam('action');
	        $response->insert('header', $this->view->renderLayout('header.phtml','./application/views/scripts/'));    	//Hien thi header 
			$response->insert('menu', $this->view->renderLayout('menu.phtml','./application/views/scripts/'));    		//Hien thi header 		
	        $response->insert('footer', $this->view->renderLayout('footer.phtml','./application/views/scripts/')); 			
		}else{			
			$result = array();
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('','efy-js'
				,'mtl/publicTree.js,ajaxupload.3.5.js,fg.menu.js,jquery.multiselect.js,chosen'
				,','
				,'js'
				,$result);
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray(''
					,'efy-style'
					,'fg.menu.css,chosen/chosen.css,jquery.multiselect.css'
					,','
					,'css'
					,$result);	
			$result = Efy_Publib_Library::_getAllFileJavaScriptCssArray('','efy-js','mtl/reminder.js',',','js',$result);		
			$this->view->arrJsCss = Zend_Json::encode($result);	
			$baseurl=$this->_request->getbaseurl();			 
		}
	}	
	/**
	 * @author: Tuanpm
	 * @see: 20/02/2013
	 * @todo: Hien thi danh sach nhac viec
	 * Enter description here ...
	 */
	public function indexAction(){
		$objFunction = New Efy_Function_RecordFunctions();	
		$objModel = new mtl_modReminder();
		$staffName = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');	
		// var_dump($_SESSION['arr_all_staff']);
		$staffName = mb_strtoupper($staffName, "utf8");	
		$this->view->titleBody = "CÔNG VIỆC CẦN XỬ LÝ CỦA ĐỒNG CHÍ ".$staffName;
		$arrParameter = array(	
			'staff_id'     => $_SESSION['staff_id'],
		);
		$arrResult = $objModel->mTLSPRun('mTL_ReminderGetAll',$arrParameter, 1,0);
		$training_count = 0;$learning_count = 0;
		if($arrResult[0]['TRAINING_IDEA'] > 0) 
			$training_count++;
		if($arrResult[0]['TRAINING_REFUSED']>0) 
			$training_count++;
		if($arrResult[0]['TRAINING_APPROVE']>0)
			$training_count++;
		if($arrResult[0]['LEARNING_REFUSED']>0)
			$learning_count++;
	    if($arrResult[0]['LEARNING_APPROVE']>0)
			$learning_count++;
		
		// $count = ($training_count > $learning_count)?$training_count:$learning_count;
		$this->view->training_count = $training_count;
		$this->view->learning_count = $learning_count;
		$this->view->arrResult = $arrResult;
	}
	

}